package com.team5101.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.team5101.entity.NextFilm;
import com.team5101.service.INextFilmService;
import com.team5101.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("api/nextfilm")
public class NextFilmController {

    @Autowired
    private INextFilmService nextFilmService;

     //分页查询代码
    @RequestMapping("/getAllfilms")
    public R getAllfilms(int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<NextFilm> list = nextFilmService.getList();
        PageInfo<NextFilm> pageInfo = new PageInfo<NextFilm>(list);
        return R.ok(pageInfo);
    }
    //测试前端
//    @RequestMapping("/getfilms")
//    public R getAllfilms(){
//        List<NextFilm> list = nextFilmService.getList();
//
//        return R.ok(list);
//    }


    @RequestMapping("/getfilm/{nfId}")
    public R getfilm(@PathVariable Integer nfId){
        NextFilm film = nextFilmService.getfilm(nfId);
        return R.ok(film);
    }


    @RequestMapping("/updata")
    public R updateFilm(NextFilm nextFilm){
        if(nextFilmService.updatafilm(nextFilm)>=1){
            return R.ok("修改成功");
        }
        return R.error();
    }


    @RequestMapping("/addfilm")
    public R addFilm(NextFilm nextFilm){
        int i = nextFilmService.addfilm(nextFilm);
          if(i>=1){
        return R.ok();
          }
              return R.error();
    }


    @RequestMapping("/removefilm")
    public R deleteFilm(Integer id){
        int deletefilm = nextFilmService.deletefilm(id);
        if(deletefilm>=1){
            return R.ok();
        }
        return R.error();
    }

    @RequestMapping("/nameis")
    public R getListByName( String nfName){
        List<NextFilm> listByName = nextFilmService.getListByName(nfName);

        return R.ok(listByName);
    }

}
